package com.airnewslinkosky.ticket.adapter;

import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.airnewslinkosky.ticket.R;

public class ListViewAdapter extends BaseAdapter {

	Activity activity;
	List<HashMap<String, Object>> list;
	public ListViewAdapter(Activity activity,List<HashMap<String, Object>> list)
	{
	  this.activity=activity; 
	  this.list = list;
	} 

	
	public int getCount() {
		return list.size();
	}

	public Object getItem(int position) {
		return list.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		 //得到自己定义的List的界面style
		  View view=activity.getLayoutInflater().inflate(R.layout.passenger_common_row,null);
		  //得到文本框1对象
		  TextView textView1=(TextView)view.findViewById(R.id.passengerName);
		  //得到文本框2对象
		  TextView textView2=(TextView)view.findViewById(R.id.idType);
		//得到文本框3对象
		  TextView textView3=(TextView)view.findViewById(R.id.idNo);
		  //得到check对象
		  CheckBox checkBox=(CheckBox)view.findViewById(R.id.CheckBox01);
		  //设置tag,为了下面的事件服务
		  checkBox.setTag(position);
		  
		  //设置文本框1对象的值
		  textView1.setText(list.get(position).get("passengerName").toString()) ;
		  //设置文本框2对象的值
		  textView2.setText(list.get(position).get("idType").toString());
		//设置文本框3对象的值
		  textView3.setText(list.get(position).get("idNo").toString());
		  //设置check对象的点击事件
		  checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
		  {   
		   public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
		   {
		    //得到tag主要传递position
		    int p= Integer.parseInt(buttonView.getTag().toString());
		    //一个简单的测试，看看有没有效果
		    Log.i("" , "*************************"+p);    
		    if(isChecked)
		    {       
		    	list.get(p).put("isCheck", "1");
		    }
		    else
		    {
		    	list.get(p).put("isCheck", "0");
		    }
		    //一个简单的测试，看看有没有效果
		    Log.i("isCheck ",list.get(p).get("isCheck").toString());
		   }
		  });  
		  return view;

	}

}
